package com.wteam.controller;

import com.wteam.PoJo.VO.LoginMember;
import com.wteam.PoJo.VO.login;
import com.wteam.PoJo.VO.member;
import com.wteam.service.MemberService;
import com.wteam.untils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@Slf4j
@RestController
@Api(tags = "用户登录注册接口")
public class LoginController {
    @Autowired
    private MemberService memberService;

    /**
     *
     * @param member
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "注册用户")
    @PostMapping("/regist")
    public Result regist(@RequestBody @Valid member member) throws Exception {
        log.info(member.toString());
        memberService.save(member);
        return Result.success();
    }

    /**
     *
     * @param login
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "登录")
    @PostMapping("/login")
    public Result<LoginMember> login(@RequestBody login login) throws Exception {
        log.info(login.toString());
        return memberService.list(login);

    }


}
